<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/static/css/login.css">
<script type="text/javascript"
	src="${pageContext.request.contextPath }/static/js/jquery-2.1.3.min.js"></script>

<title>My JSP 'login.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

<script type="text/javascript">
	function login() {
		var username = $("#username").val();
		var password = $("#password").val();
		var verifycode = $("#verifycode").val();
		$.ajax({
					type : "POST",
					url : "${pageContext.request.contextPath}/loginController/check.do",
					data : {
						"username" : username,
						"password" : password,
						"verifycode" : verifycode
					},
					async : false,
					cache : false,
					success : function(data) {
						if (data == "default") {
							alert("账号密码错误");
							$("#username").val("");
							$("#password").val("");
						} else if(data == "verifycode"){
							alert("验证码输入错误");
							$("#verifycode").val("");
						} else{
							alert("登陆成功");
							window.location.href = "${pageContext.request.contextPath}/bookController/showBook.do";
						}

					},
					error : function() {
						alert("系统错误");
					}
				});
	}
	function back() {
		window.location.href = "${pageContext.request.contextPath}/welcomeController/welcome.do";
	}
	//获取随机验证码
	function reloadVerifyCode() {
		var imgSrc = $("#send");
		imgSrc.attr("src",
				"${pageContext.request.contextPath}/servlet/imageServlet?d="
						+ new Date());
	}
</script>

</head>

<body>
	<div class="main ">
		<div class="content ">
			<span>账号：</span> <input name="username" id="username" /> <br /> 
			<span>密码：</span> <input name="username" id="password" /> <br /> 
			<span>验证码：</span> <input name="verifycode" id="verifycode" />
			<img id="send"
				class="decoded checkCode" title="点击图片刷新验证码"
				onclick="reloadVerifyCode()"
				src="${pageContext.request.contextPath}/servlet/imageServlet"
				style="cursor:pointer;position:relative;top:5px;float:right">
		</div>
		<div class="choice ">
			<button id="login_btn" onclick="login()">登陆</button>
			<button id="back_btn" onclick="back()">返回</button>
		</div>
	</div>
</body>
</html>
